package com.cropflow.repository;

import com.cropflow.entity.MaintenanceRecord;
import com.cropflow.entity.Vehicle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface MaintenanceRecordRepository extends JpaRepository<MaintenanceRecord, Long> {
    
    List<MaintenanceRecord> findByVehicleId(Long vehicleId);
    
    List<MaintenanceRecord> findByStatus(MaintenanceRecord.MaintenanceStatus status);
    
    @Query("SELECT m FROM MaintenanceRecord m WHERE m.scheduledDate BETWEEN :start AND :end")
    List<MaintenanceRecord> findByScheduledDateBetween(LocalDateTime start, LocalDateTime end);
    
    List<MaintenanceRecord> findByType(MaintenanceRecord.MaintenanceType type);
    
    // 添加方法
    List<MaintenanceRecord> findByVehicleOrderByStartTimeDesc(Vehicle vehicle);
}